%@ LANGUAGE="VBSCRIPT"%>
<%OPTION EXPLICIT%>
<%Response.Buffer = True%>
<%
Set objConn = Server.CreateObject ("ADODB.Connection")
Set objRec = Server.CreateObject ("ADODB.Recordset")
Set objRec2 = Server.CreateObject ("ADODB.Recordset")
objConn.Open strconnect
objRec.Open "cats", objConn, adOpenDynamic, adLockPessimistic, adCmdTable
objRec2.Open "links", objConn, adOpenStatic, adLockReadOnly, adCmdTable
Dim NewCatTitle
Dim NewCatDesc
NewCatTitle = Replace(Request.Form("CurrentCatTitle"), "'", "''", 1)
NewCatDesc = Replace(Request.Form("CurrentCatDesc"), "'", "''", 1)
%>
Admin Panel - Add/Update Categories
<%
' Display the page body.
Response.Write LSPageBody1
'Check to see if they have the password in either a cookie or form response.
If (Request.Form("Password") = LSAdminPassword) OR (Request.Cookies(""&Session.SessionID&"") = LSAdminPassword) Then
'Update the cookie.
Response.Cookies(""&Session.SessionID&"") = LSAdminPassword
'If there is somethin in the form field cattitle, then
If NOT Request.Form("cattitle") = "" then
'Add the new category.
objRec.AddNew
objRec("CatTitle") = Request.Form("cattitle")
objRec("CatDesc") = Request.Form("catdesc")
If NOT Request.QueryString("catid") = "" then
objRec("ParentID") = Request.Querystring("catid")
End If
objRec.Update
End If
'If there is a cat ID, it's not the top level so
If NOT Request.QueryString("catid") ="" then
'If the update form has been submitted then
If Request.Form("update") = "true" then
'update the current category.
strSQL = "UPDATE cats SET CatTitle='"&NewCatTitle&"' WHERE CatID = "&Request.QueryString("CatID")
Set objRec = objConn.Execute (strSQL, ,adCmdText)
End If
End If
Else
If NOT Request.Form("Password") = "" Then
Response.Write FONT1 & "Sorry. Incorrect password. Try again.
"
End If
End If
%>
<%
Dim arCatIDs()
Redim arCatIDs(1)
Dim arCatTitles()
Redim arCatTitles(1)
Dim i
Dim ArraySize
CatID = Request.QueryString("CatID")
If Request.QueryString("CatID") = "" then CatID = 0 End If
'Create a recordset with the top level categories in it.
strSQL = "SELECT * FROM Cats ORDER BY CatTitle ASC;"
Set objRec = objConn.Execute (strSQL)
Sub FillArray
i = 0
'Loop until the top level category is found.
DO UNTIL CatID = 0
'Create a filtered recordset with only one record.
objRec.Filter = "CatID = " & CatID
arCatIDs(i) = objRec("CatID")
arCatTitles(i) = objRec("CatTitle")
If NOT objRec("ParentID") = 0 then
Redim Preserve arCatIDs(i+1)
Redim Preserve arCatTitles(i+1)
End If
CatID = objRec("ParentID")
i = i + 1
LOOP
End Sub
FillArray
Response.Write FONT2
'It might be the top level in which case Home shouldn't be a link.
If NOT Request.QueryString("CatID") = "" then
If Request.QueryString("admin") = "" then
Response.Write "Home >> "
Else
'If this page is being used on the Add Category Admin Page then
If Request.QueryString("admin") = "addcat" then
Response.Write "Home >> "
End If
'If this page is being used on the Delete Link Admin Page then
If Request.QueryString("admin") = "dellink" then
Response.Write "Home >> "
End If
End If
Else
Response.Write "Home >> "
End If
'The array holds the information in the wrong order so read it backwards.
For i = UBound(arCatIDs) to 0 Step - 1
If i = 0 then
Response.Write arCatTitles(i)
Else
'This is a stupid line of code. Remove it and see what happens to the first level of categories.
If NOT arCatIDs(i) = "" then
If Request.QueryString("admin") = "" then
'Write this if the page is being used on the display pages.
Response.Write ""&arCatTitles(i)&" : "
Else
'Write this if it is the add category admin page.
If Request.QueryString("admin") = "addcat" then
Response.Write ""&arCatTitles(i)&" : "
End If
'Write this if it is the delete link admin page.
If Request.QueryString("admin") = "dellink" then
Response.Write ""&arCatTitles(i)&" : "
End If
End If
End If
End If
Next
Response.Write ""
%>
<%
Dim objRec3
Set objRec3 = Server.CreateObject ("ADODB.Recordset")
objRec3.Open "cats", objConn, adOpenStatic, adLockReadOnly, adCmdTable
CatID = Request.QueryString("CatID")
If Request.QueryString("CatID") = "" then CatID = 0 End If
'Create a recordset with the top level categories in it.
strSQL = "SELECT * FROM Cats WHERE ParentID= "& CatID &" ORDER BY CatTitle ASC;"
set objRec = objConn.Execute (strSQL)
Sub DisplayCats()
Response.Write LSCatCells & FONT1 & ""
If objRec.EOF then
Response.Write " "
Else
'Determin whether it is being used for Admin or not.
If Request.QueryString("admin") = "" then%>
&cattitle=<%=Replace(objRec("CatTitle"), " ", "+", 1)%>"><%=objRec("CatTitle")%>
<%Else
If Request.QueryString("admin") = "addcat" then%>
&admin=addcat"><%=objRec("CatTitle")%>
<%End If
If Request.QueryString("admin") = "dellink" then%>
&admin=dellink"><%=objRec("CatTitle")%>
<%End If%>
<%End If
Response.Write FONT3
objRec2.Filter = "CatID="&objRec("CatID")
'Display amount of resources.
If objRec2.RecordCount = 1 then
Response.Write "(1 Resource) "
Else
Response.Write "(" & objRec2.RecordCount & " Resources) "
End If
objRec2.Filter = 0
objRec3.Filter = "ParentID="&objRec("CatID")
'Display the amount of categories.
If objRec3.RecordCount = 1 then
Response.Write "(1 Category)"
Else
Response.Write "(" & objRec3.RecordCount & " Categories)"
End If
objRec3.Filter = 0
Response.Write ""
'Display the descrition for the category if one exists.
If NOT objRec("CatDesc") = "" then
Response.Write "
" & FONT2 & objRec("CatDesc")
End If
objRec.MoveNext
End If
Response.Write ""
End Sub
If not objRec.EOF then
'Add the table HTML for the categories.
Response.Write LSCatsTable
'Loop to step through the records in the categories recordset.
Do Until objRec.EOF
Response.Write ""
DisplayCats
DisplayCats
Response.Write "
"
LOOP
Response.Write ""
Response.Write "
"
End If
'Have a quick tidy up. If only house work was this easy.
objRec3.Close
Set objRec3 = Nothing
%>
|
<%If NOT Request.QueryString("catid") ="" then
strSQL = "SELECT * FROM Cats WHERE CatID= "& Request.QueryString("catid") &""
set objRec = objConn.Execute (strSQL)
%>
<%
End If
'Have a quick tidy up. If only house work was this easy.
objRec.Close
objConn.Close
Set objRec = Nothing
Set objConn = Nothing%> |